package com.comm.user.service;

import java.util.List;
import java.util.Map;


import jcf.sua.dataset.GridData;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.comm.user.model.User;
import com.comm.user.sql.UserSql;
import com.comm.user.sql.UserSql2;

import jcf.dao.ibatis.crud.util.DefaultSaveStatusMapping;
import jcf.dao.ibatis.crud.util.SaveStatusMapping;
import jcf.hanyang.dao.CommonDAO;
import jcf.sua.dataset.RowStatus;

@Service
public class UserService { 
	@Autowired(required=false)
	private CommonDAO dao;
	
	/* ******************************** SERVICE METHODS ****************************** */

	public List findAllDaneos(Map paramMap) {
		//return dao.queryForList(UserSql.selectUser(), paramMap);
		return dao.queryForList(UserSql.selectDaneo(), paramMap);
	}
	
	public List findAllDaneos2(Map paramMap) {
		//return dao.queryForList(UserSql.selectUser(), paramMap);
		return dao.queryForList(UserSql2.selectDaneo(), paramMap);
	}
	
	public void saveDaneos(GridData<User> gridData) {
		for (int index  = 0; index < gridData.getList().size(); index++) {
			User user = gridData.getList().get(index);
			RowStatus status = gridData.getStatusOf(index);
			if (status.equals(RowStatus.INSERT)) { // "INSERT"
				dao.update(UserSql2.insertDaneo(), user);
			}
			else if (status.equals(RowStatus.UPDATE)) { // "INSERT"
				dao.update(UserSql2.updateDaneo(), user);
			}
			else if (status.equals(RowStatus.DELETE)) { // "INSERT"
				dao.update(UserSql2.deleteDaneo(), user);
			}
			else throw new RuntimeException(
					"상태값 오류. [ 상태값 : "
					+ status
					+ " ], [ 상태옵션 : "
					+ status + " ]");
		}
	}
}